# -*- coding: UTF-8 -*-

from types import *

from Cheetah.Template import Template

import getTabList
import os

class createList:  
  
  def __init__(self):
    self.tables = []
    self.dirs = ['action', 'business', 'form', 'orm']
    self.path = os.getcwd()
    self.sqloutput = open("struts-conf.xml", 'w') 
    
    print "init... "
    
  def set(self, tables):
      self.tables = tables

  def run(self):
    nameSpace = {'tables':self.tables} 
    sp = Template(file="template.xml", searchList=[nameSpace])
    sp = "%s"%(sp)
    self.sqloutput.writelines(sp)
  
  def mkdir(self, path):
    if not os.path.exists(path):
      #print "make dir"
      os.mkdir(path)
      
  def makedir(self):
    #com.kylin.module.address.action
    # dir list: action, business, form, orm,    
    #path = os.getcwd()
    src =  self.path + "\\src"
    self.mkdir(src)
    
    
    for x in self.tables:
      objdir = src + "\\" +x
      self.mkdir(objdir)
      for y in self.dirs:
        subdir = objdir +"\\" +y
        self.mkdir(subdir)
    
    
  def __del__(self):
    pass
    #input.close()
    
if __name__ == "__main__":
    tabs = getTabList.gettables()
    d = createList()
    d.set(tabs)
    d.run()
    #d.makedir()
